package ru.digitanoise.dnaccountapi.mapper;

import org.springframework.stereotype.Component;
import ru.digitanoise.dnaccountapi.models.dto.AccountResponseDTO;
import ru.digitanoise.dnaccountapi.models.dto.RegistrationAccountRequestDTO;
import ru.digitanoise.dnaccountapi.models.entity.Account;

@Component
public class AccountMapper {

    public AccountResponseDTO map(Account account) {
        AccountResponseDTO accountResponseDTO = new AccountResponseDTO();
        accountResponseDTO.setEmail(account.getEmail());
        accountResponseDTO.setFirstname(account.getFirstname().trim());
        accountResponseDTO.setLastname(account.getLastname().trim());
        accountResponseDTO.setUsername(account.getUsername().trim());
        return accountResponseDTO;
    }

    public Account map(RegistrationAccountRequestDTO registrationAccountRequestDTO) {
        Account account = new Account();
        account.setEmail(registrationAccountRequestDTO.getEmail());
        account.setFirstname(registrationAccountRequestDTO.getFirstname());
        account.setLastname(registrationAccountRequestDTO.getLastname());
        account.setUsername(registrationAccountRequestDTO.getUsername());
        account.setPassword(registrationAccountRequestDTO.getPassword());
        return account;
    }
}
